unit uListagemCaixa;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uListagemPadrao, Grids, DBGrids, RXDBCtrl, StdCtrls, Buttons,
  ExtCtrls, DB;

type
  TfListCaixa = class(TfListagemPadrao)
    DataSource1: TDataSource;
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure SpeedButton2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fListCaixa: TfListCaixa;

implementation

uses uCadCaixa, uDm, uPrincipal;

{$R *.dfm}

procedure TfListCaixa.SpeedButton1Click(Sender: TObject);
begin
  inherited;
  try
    Application.CreateForm(TfCadCaixa, fCadCaixa);
    dm.qryCaixa.close;
    dm.qryCaixa.Open;
    dm.qryCaixa.Insert;
    fCadCaixa.showmodal;
  finally
    FreeAndNil(fCadCaixa);
    dm.qryCaixa.Close;
    dm.qryCaixa.Open;
  end;
end;

procedure TfListCaixa.FormShow(Sender: TObject);
begin
  inherited;
  dm.qryCaixa.Close;
  dm.qryCaixa.Open;
end;

procedure TfListCaixa.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
  inherited;
  if odd(dm.qryCaixa.RecNo) then
    DBGrid1.Canvas.Brush.Color:= fPrincipal.linhaEscura
  else
    DBGrid1.Canvas.Brush.Color:= fPrincipal.linhaClara;

  TDbGrid(Sender).Canvas.font.Color:= clBlack;
    if gdSelected in State then
      with (Sender as TDBGrid).Canvas do
        begin
          Brush.Color := fPrincipal.linhaSelecionada;
          FillRect(Rect);
          Font.Style := [fsbold]
        end;

  TDbGrid(Sender).DefaultDrawDataCell(Rect, TDbGrid(Sender).columns[datacol].field, State);
end;

procedure TfListCaixa.SpeedButton2Click(Sender: TObject);
begin
  inherited;
  try
    Application.CreateForm(TfCadCaixa, fCadCaixa);
    dm.qryCaixa.Edit;
    fCadCaixa.showmodal;
  finally
    FreeAndNil(fCadCaixa);
    dm.qryCaixa.Close;
    dm.qryCaixa.Open;
  end;
end;

end.
